/**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:com.cesgroup.zw.spring.boot.util</p>
 * <p>File:JavaScriptSerializer.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 May 29, 2019 4:26:04 PM
 */
package com.cesgroup.zw.spring.boot.supports.jackson;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date May 29, 2019 4:26:04 PM
 * @version 1.0.2019
 */
public class JavaScriptSerializer extends JsonSerializer<String> {

	/**
	 * @see com.fasterxml.jackson.databind.JsonSerializer#serialize(java.lang.Object, com.fasterxml.jackson.core.JsonGenerator, com.fasterxml.jackson.databind.SerializerProvider)
	 * @author chanlong(陈龙)
	 * @date May 29, 2019 4:26:54 PM
	 */
	@Override
	public void serialize(String value, JsonGenerator gen, SerializerProvider provider) throws IOException {
		if (value.startsWith("function") || value.startsWith("[")|| value.trim().startsWith("new")) {
			gen.writeRawValue(value);
		} else {
			gen.writeString(value);
		}
	}
}
